<template>
  <div class="app-container">
    <el-tabs type="border-card" @tab-click="handleClick" v-model="activeName">
      <el-tab-pane name="one">
        <span slot="label">  <i class="el-icon-date"></i>七牛云对象存储</span>
        <el-form
          style="margin-left: 20px;"
          label-position="left"
          :model="form"
          label-width="120px"
          :rules="rules"
          ref="form"
        >
          <aside>
            使用 <a href="http://www.moguit.cn/#/info?blogUid=735ed389c4ad1efd321fed9ac58e646b">七牛云</a> 构建对象存储服务<br/>
          </aside>

          <el-form-item label="七牛云文件域名" prop="qiNiuPictureBaseUrl">
            <el-input v-model="form.qiNiuPictureBaseUrl" style="width: 400px" placeholder="例如：http://images.xxx.cn/"></el-input>
          </el-form-item>

          <el-form-item label="七牛云公钥">
            <el-input v-model="form.qiNiuAccessKey" style="width: 400px"></el-input>
          </el-form-item>

          <el-form-item label="七牛云私钥">
            <el-input type="password" v-model="form.qiNiuSecretKey" style="width: 400px"></el-input>
          </el-form-item>

          <el-form-item label="上传空间">
            <el-input  v-model="form.qiNiuBucket" style="width: 400px"></el-input>
          </el-form-item>

          <el-form-item label="存储区域">
            <el-select v-model="form.qiNiuArea" placeholder="请选择存储区域" clearable>
              <el-option v-for="item in areaDictList"
                         :key="item.dictValue"
                         :label="item.dictLabel"
                         :value="item.dictValue"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="submitForm()">保 存</el-button>
          </el-form-item>

        </el-form>
      </el-tab-pane>
    </el-tabs>
    
  </div>
</template>

<script>
import { getSystemConfig, editSystemConfig} from "@/api/system/hyConfig";

export default {
  name: "Config",
  data() {
    return {
      form: {

      },
      index: "0", // 当前激活页
      activeName: "one",
      areaDictList: [], //存储区域字典

      rules: {
        localPictureBaseUrl: [
          {pattern: /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/, message: '请输入正确的域名'},
        ],
        qiNiuPictureBaseUrl: [
          {pattern: /^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+/, message: '请输入正确的域名'},
        ],
        email: [
          {pattern: /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/, message: '请输入正确的邮箱'},
        ],
      }
    };
  },
  created() {
    // 获取字典
    this.getDict()
    // 获取系统配置
    this.getSystemConfig()
  },
  methods: {
    getDict: function() {
      this.getDicts("qiniu_storage_region").then(response => {
        this.areaDictList = response.data;
      });
    },
    getSystemConfig: function() {
      getSystemConfig().then(response => {
        if (response.data) {
          this.form = response.data;
        }
      });
    },
    // 保存按钮
    submitForm: function() {
      console.log("开始提交表单")
      this.$refs["form"].validate(valid => {
        if (valid) {
          editSystemConfig(this.form).then(response => {
            this.msgSuccess("保存成功");
            this.open = false;
            this.getList();
          });
          
        }
      });
    },
  }
};
</script>
